package com.fantasy.easy.biz.utils;

import org.springframework.core.io.ClassPathResource;
import java.io.InputStream;
import java.awt.*;

/**
 * @Description TODO
 * @Author sdehua-帅德华
 * @Email sdhstart@qq.com
 * @Date 2022/6/27 11:05
 * @Version 1.0
 **/
public class FontUtil {
    /**
     * 导入本地字体 防止linux下汉字乱码
     *
     * @param style 字体类型
     * @param size  字体大小
     * @return 字体
     */
    public static Font loadFontResource(int style, int size) {
        InputStream resourceAsStream = null;
        try {
//            取消导入本地字体
//            ClassPathResource classPathResource = new ClassPathResource("./font/MSYH.TTF");
//            System.out.println(classPathResource.getPath());
//            resourceAsStream = classPathResource.getInputStream();
//            Font font = Font.createFont(Font.TRUETYPE_FONT, resourceAsStream);
            Font font = new Font("font",style,size);
            return font.deriveFont(style, size);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
